<?php

function generateRandomCode()
{
	$retVal = md5(time()."PrijsGezocht".rand(1, 9998999));
	return $retVal;
}

function generateShopUserActivationcode()
{
	global $mysqli;
	$retVal = generateRandomCode();
	$query = "SELECT 
				ID 
			FROM Customers 
			WHERE ActivationCode = '" . str_replace("'", "", $retVal) . "'";
	$result = $mysqli->query($query);
	$number = $result->num_rows;
	if($number >= 1)
		$retVal = generateActivationcode();
	return $retVal;
}

function generatePasswordResetCode()
{
	global $mysqli;
	$retVal = generateRandomCode();
	$query = "SELECT 
				ID 
			FROM Customers 
			WHERE PasswordResetCode = '" . str_replace("'", "", $retVal) . "'";
	
	$result = $mysqli->query($query);
	$number = $result->num_rows;
	if($number >= 1)
		$retVal = generatePasswordResetCode();
	return $retVal;
}

function generateActivatiecode()
{
	global $_MySQL;
	$retVal = generateRandomCode();
	$query = "SELECT * FROM LanceringsLeden WHERE ActivatieCode = '".$retVal."'";
	$result = $_MySQL->runQuery($query);
	if(mysql_num_rows($result)>=1)
		$retVal = generateActivatiecode();
	return $retVal;
}
?>
